# -*- coding: utf-8 -*-
from flask import jsonify, request
from flask import Blueprint
from connect_mysql import MySQL_db
import matlab
import matlab.engine
import sys

reload(sys)
sys.setdefaultencoding("utf-8")

yuyi = Blueprint("yuyi", __name__)


# 测试接口
@yuyi.route("/test", methods=["POST"])
def Test():
    return "OK"


# 前端传入疾病信息、省份、城市以及用户查询医生指标的参数，参数通过表单方式传入，通过基于相对属性学习模型计算出医生的评分，然后推荐给用户
# 1代表医生评分  2代表疾病擅长   3代表问诊量   4代表关注度    5代表活跃度    6代表预约量    7代表服务态度
@yuyi.route("/Doctor_Recommend", methods=["POST"])
def get_doctor_info():
    cursor = MySQL_db()
    disease_id = []
    disease_id.append(int(request.form["Disease_id"]))
    province = request.form["Province"]
    city = request.form["City"]
    star = request.form["Star"]
    skilled_disease = request.form["Skilled_disease"]
    outpatient = request.form["OutPatient"]
    attention = request.form["Attention"]
    remark = request.form["Remark"]
    order = request.form["Order"]
    attitude = request.form["Attitude"]
    attributes_list = []
    if star:
        attributes_list.append(int(star))
    if skilled_disease:
        attributes_list.append(int(skilled_disease))
    if outpatient:
        attributes_list.append(int(outpatient))
    if remark:
        attributes_list.append(int(remark))
    if attention:
        attributes_list.append(int(attention))
    if order:
        attributes_list.append(int(order))
    if attitude:
        attributes_list.append(int(attitude))
    if not attributes_list:
        attributes_list.append(1)
    print attributes_list
    eng1 = matlab.engine.connect_matlab()
    doctor_info = eng1.Doctor_Recommend(matlab.double(disease_id), matlab.double(attributes_list))
    eng1.quit()
    '''
    eng1 = matlab.engine.connect_matlab()
    doctor_info = eng1.Doctor_Recommend(matlab.double([74]), matlab.double([1, 2, 3]))
    eng1.quit()
    '''
    print doctor_info
    data = cursor.select_info(doctor_info)
    return jsonify(data)
